package game.phases.actionphase.commands 
{
	import core.Command;
	import game.mapviewer.popups.battle.BattlePopup;
	
	/**
	 * ...
	 * @author rnk
	 */
	public class GetTacticsCommand extends Command
	{
		private var sides:Array;
		private var tactics:Array=[];
		private var bPopup:BattlePopup;
		private var currentIdx:int = -1;
		
		
		public function GetTacticsCommand(sides:Array, bPopup:BattlePopup) 
		{
			this.sides = sides;
			this.bPopup = bPopup;
		}
		
		override public function Execute():void 
		{
			super.Execute();
			
			AskNextArmy();
		}
		
		private function OnAnswer(selectedTactics:int):void
		{
			tactics.push(selectedTactics);
			
			AskNextArmy();
		}
		
		private function AskNextArmy():void
		{
			//show panel
			currentIdx++;
			
			if (currentIdx < sides.length)
				bPopup.AskTactics(sides[currentIdx].player,sides[currentIdx].power,sides[currentIdx].isAttacking, OnAnswer);
			else
			{
				callbackParams = [tactics];
				Callback();
			}
		}
		
	}

}